package model;

/**
 * @author wujiazhan
 * @className Differential
 * @description 微分器
 * @date 2021-05-19 11:01
 */
@SuppressWarnings("all")//去除所有警告
public class Differential {
    private double pre_val = 0.0; //前一拍的值
    private double samplingTime;

    public Differential(double samplingTime){
        this.samplingTime = samplingTime;
    }

    /**
     * 微分值
     * @param input_cur 当前拍的值
     * @return 微分值
     */
    public double getDiff(double input_cur){
        double res = (input_cur - pre_val) / samplingTime;
        pre_val = input_cur; //更新状态值
        return res;
    }

    /**
     * 获取前一拍状态值
     *
     * @return double
     */
    public double getPre_val(){
        return pre_val;
    }


    /**
     * 设置前一拍状态值
     *
     * @param input_val 输入值
     */
    public void setPre_val(double input_val){
        this.pre_val = input_val;
    }
}
